package be.sc.classicnetwork.dao.hibernate;

import java.util.List;

import org.hibernate.criterion.Order;

import be.sc.classicnetwork.dao.ContactDao;
import be.sc.classicnetwork.model.Car;
import be.sc.classicnetwork.model.Contact;

/**
 * ContactDaoImpl.
 */
public class ContactDaoImpl extends HibernateGenericDao<Contact> implements ContactDao {

    /**
     * Constructor.
     */
    public ContactDaoImpl() {
	super();
    }

    /**
     * @param clazz
     */
    public ContactDaoImpl(Class<Contact> clazz) {
	super(clazz);
    }

    /**
     * Unpublishes the specified contact.
     */
    @Override
    public void delete(Contact entity) {
	entity.setPublished(false);
	this.saveOrUpdate(entity);
    }

    /**
     * @see be.sc.classicnetwork.dao.hibernate.HibernateGenericDao#findAll(int,
     *      int)
     */
    @Override
    public List<Contact> findAll(int first, int max) {
	getHibernateTemplate().enableFilter(Car.PUBLISHED_FILTER);
	return findByCriteria(0, 0, null, null, new Order[] { Order.asc("lastName") });
    }

}
